/**
 * 资源分类
 */

import request from '@/utils/request'

export interface RolePages {
  code?: string;
  id?: number;
  name?: string;
  startCreateTime?: string;
  endCreateTime?: string;
  current?: number;
  size?: number;
}

export interface AllocateUserRoles {
  userId: number;
  roleIdList?: number[];
}

/** 按条件查询角色 */
export const getRolePages = (data: RolePages) => {
  return request({
    method: 'POST',
    url: '/boss/role/getRolePages',
    data
  })
}

/** 保存或者更新角色 */
export const createOrUpdate = (data: RolePages) => {
  return request({
    method: 'POST',
    url: '/boss/role/saveOrUpdate',
    data
  })
}

/** 删除角色 */
export const deleteRole = (id: number) => {
  return request({
    method: 'DELETE',
    url: `/boss/role/${id}`
  })
}

/** 获取角色 */
export const getRoleById = (id: number | string) => {
  return request({
    method: 'GET',
    url: `/boss/role/${id}`
  })
}

/** 获取所有角色 */
export const getAllRoles = () => {
  return request({
    method: 'GET',
    url: '/boss/role/all'
  })
}

/** 给用户分配角色 */
export const allocateUserRoles = (data: AllocateUserRoles) => {
  return request({
    method: 'POST',
    url: '/boss/role/allocateUserRoles',
    data
  })
}

/** 给用户分配角色 */
export const getUserRoles = (id: number | string) => {
  return request({
    method: 'GET',
    url: `/boss/role/user/${id}`
  })
}
